package com.cn.mmd.service;

import com.cn.mmd.mapper.*;
import com.cn.mmd.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/6/24 0024.
 */
@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Autowired
    private TeacherDataMapper teacherDataMapper;

    @Autowired
    private TeacherStatisticsMapper teacherStatisticsMapper;
    @Autowired
    TeacherRankingMapper teacherRankingMapper;
    @Autowired
    AvgSchoolMapper avgSchoolMapper;
    @Autowired
    AvgCollegeMapper avgCollegeMapper;
    @Autowired
    WeekStatisticsMapper weekStatisticsMapper;
    /**
     * 教师端登录
     * @param teacherid
     * @param teacherpassword
     * @return
     */
    @Override
    public TeacherData teacherLogin(String teacherid,String teacherpassword){
        System.out.println("进入service方法");
        return teacherDataMapper.selectByPrimaryKey(teacherid);
    }

    /**
     * 查询当前老师的统计次数
     * @param teacherid
     * @return
     */
    @Override
    public TeacherStatistics selectStatistics(String teacherid) {
        TeacherStatistics teacherStatistics = teacherStatisticsMapper.selectByPrimaryKey(teacherid);

        return teacherStatistics;

    }
    /**
     * 修改统计次数
     * @param teacherStatistics
     * @return
     */
    @Override
    public int updateStatistics(TeacherStatistics teacherStatistics){

        int i=teacherStatisticsMapper.updateByPrimaryKeySelective(teacherStatistics);
        return i;
    }

    /**
     * 添加老师统计
     * @param teacherStatistics
     * @return
     */
    public int insertStatistics(TeacherStatistics teacherStatistics){
        return teacherStatisticsMapper.insertSelective(teacherStatistics);
    }

    /**
     * 通过教师工号查询该教师所有信息
     * @param teacherid
     * @return
     */
    @Override
    public TeacherData selectByTeacherId(String teacherid){
        return teacherDataMapper.selectByPrimaryKey(teacherid);
    }


    /**
     * 修改教师信息
     * @param
     * @return
     */
    @Override
    public int updateTeacher(TeacherData teacherData){
        int i=teacherDataMapper.updateByPrimaryKeySelective(teacherData);

        return i;
    }


    /**
     * 查询老师评价分数及排名
     * @param teacherId
     * @return
     */

    public TeacherRanking selectTeacherRanking(String teacherId){
        return teacherRankingMapper.selectByPrimaryKey(teacherId);
    }


    /**
     * 修改老师评价分数及排名
     * @param teacherRanking
     * @return
     */
    public int updateTeacherRanking(TeacherRanking teacherRanking){

        return teacherRankingMapper.updateByPrimaryKeySelective(teacherRanking);
    }


    /**
     * 添加老师评价分数及排名
     * @param teacherRanking
     * @return
     */
    public int insertTeacherRanking(TeacherRanking teacherRanking){

        return teacherRankingMapper.insertSelective(teacherRanking);
    }


    /**
     * 查询学校平均分及详情
     * @return
     */
    public AvgSchool selectAvgSchool(){

        return avgSchoolMapper.selectAvgSchool();
    }


    /**
     * 修改学校平均分及详情
     * @param avgSchool
     * @return
     */
    public int updateAvgSchool(AvgSchool avgSchool){
        return avgSchoolMapper.updateByPrimaryKeySelective(avgSchool);
    }


    /**
     * 添加学校平均分及详情
     * @param avgSchool
     * @return
     */
    public int insertAvgSchool(AvgSchool avgSchool){
        return avgSchoolMapper.insertSelective(avgSchool);
    }


    /**
     * 查询老师主表
     * @param teacherId
     * @return
     */
    public Teacher serlectTeacher(String teacherId){
        return teacherMapper.selectByPrimaryKey(teacherId);
    }



    /**
     * 查询学院平均分及详情
     * @return
     */
    public AvgCollege selectAvgCollege(String schoolCollegeId){
        return avgCollegeMapper.selectByPrimaryKey(schoolCollegeId);
    }

    /**
     * 修改学院平均分及详情
     * @param avgCollege
     * @return
     */
    public int updateAvgCollege(AvgCollege avgCollege){
        return avgCollegeMapper.updateByPrimaryKeySelective(avgCollege);
    }


    /**
     * 添加学院平均分及详情
     * @param avgCollege
     * @return
     */
    public int insertAvgCollege(AvgCollege avgCollege){
        return avgCollegeMapper.insertSelective(avgCollege);
    }


    /**
     * 查出所有学院的成绩信息
     * @return
     */
    public List<AvgCollege> selectAllAvgCollege(){
        return avgCollegeMapper.selectAllAvgCollege();
    }



    /**
     * 通过教师id查到比该教师得分多的人数
     * @param teacherId
     * @return
     */
    public int calculateTeacherRanking(String teacherId){
        return teacherRankingMapper.calculateTeacherRanking(teacherId);
    }


    @Override
    public List<Teacher> selectByName(String teacherName) {
        return teacherMapper.selectByName(teacherName);
    }

    @Override
    public int insertSelective(Teacher record) {
        return teacherMapper.insertSelective(record);
    }

    @Override
    public Teacher selectByidRid(String teacherid) {
        return  teacherMapper.selectByidRid(teacherid);
    }


    @Override
    public List<Teacher> selectByAllExT(String teacherid) {
        return teacherMapper.selectByAllExT(teacherid);
    }

    @Override
    public int insertSelective(TeacherData record) {
        return teacherDataMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(TeacherStatistics record) {
        return teacherStatisticsMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public TeacherStatistics selectByPrimaryKey(String teacherSid) {
        return teacherStatisticsMapper.selectByPrimaryKey(teacherSid);
    }



    @Override
    public List<Teacher> selectByPaging(Teacher teacher) {
        return teacherMapper.selectByPaging(teacher);
    }

    @Override
    public int updateByPrimaryKeySelective(Teacher record) {
        return teacherMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int deleteByPrimaryKey(String teacherSid) {
        return teacherStatisticsMapper.deleteByPrimaryKey(teacherSid);
    }

    @Override
    public Teacher selectByPrimaryKeyo(String teacherid) {
        return teacherMapper.selectByPrimaryKey(teacherid);
    }

    @Override
    public int selectCount(String teacherposition) {
        return teacherMapper.selectCount(teacherposition);
    }

    @Override
    public int countLimitNum(Teacher teacher) {
        return teacherMapper.countLimitNum(teacher);
    }
}
